// ==UserScript==
// @name			Google Analytics Row Limit Link
// @author			Erik Vold
// @namespace		gaRowLimitLink
// @include			https://www.google.com/analytics/reporting/*
// @include			https://adwords.google.com/analytics/reporting/*
// @version			0.1
// @license			GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @datecreated		2009-08-25
// @lastupdated		2009-08-25
// @description		This userscript will add a link to the result count, so that you can easily see all rows.
// ==/UserScript==


var gaRowLimitLink = {};
gaRowLimitLink.addNodeInsertListener = function() {
	document.addEventListener( "DOMNodeInserted", gaRowLimitLink.doTasks, false );
	return true;
}
gaRowLimitLink.doTasks = function() {
	try {
		gaRowLimitLink.addLink();
	}
	catch( e ) {
	}
	return true;
}
gaRowLimitLink.addLink = function() {
	var prevBtn = document.evaluate("//div[@class='pagination_controls']/a[@title='previous']", document, null, 9, null).singleNodeValue;
	if( !prevBtn ) {
		return false;
	}

	var strSpan = prevBtn.previousSibling;
	if( strSpan.className != "button_label" ) {
		strSpan = prevBtn.previousSibling.previousSibling;
	}
	if( strSpan.className != "button_label" ) {
		return false;
	}
	if( strSpan.getAttribute( "gaRowLimit" ) ) {
		return false;
	}
	var strMatch = /\s*(\d[\d\s,]*)-([\d\s,]*\d)\s+of\s+(\d[\d\s,]*\d)\s*/i.exec( strSpan.innerHTML );
	var totalRows = strMatch[3].replace( /[\s,]*/i, "" );
	strSpan.setAttribute( "gaRowLimit", totalRows );
	strSpan.innerHTML = strMatch[1] + " - " + strMatch[2] + " of " + '<a title="Display all ' + totalRows + ' rows" href="javascript:table._toggleRowShow(' + totalRows + ');">' + strMatch[3] + '</a>';

	return true;
}

// setup
gaRowLimitLink.addNodeInsertListener();